package xinyu.customer.news.data;

import com.logos.common.source.network.callback.BaseNetWorkCallBack;
import com.logos.common.source.network.entity.BaseNetEntity;
import com.logos.common.source.network.entity.FailedNetEntity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import xinyu.customer.bean.NewsMainNetTopBean;
import xinyu.customer.bean.NewsNoteBean;
import xinyu.customer.network.AppNetWork;
import xinyu.customer.network.AppUrlUtil;
import xinyu.customer.util.SpConstant;

public class NewsTabNoteRemoteDataSource implements NewsTabNoteDataSource {

    @Override
    public void getNewsTabNoteListData(int pageNum,String custId, NewsTabNoteCallback callback) {
        if (callback == null) {
            throw new IllegalArgumentException("parameter must not is empty.");
        }
        Map<String, Object> map = new HashMap<>();
        map.put("cust_id", custId);
        map.put("page", pageNum+"");
        AppNetWork.post(AppUrlUtil.getNewsNoteListData(), map, new BaseNetWorkCallBack<BaseNetEntity<List<NewsNoteBean>>>() {

            @Override
            public void onSuccess(BaseNetEntity<List<NewsNoteBean>>  content) {
                BaseNetEntity<List<NewsNoteBean>> netEntity = content;
                if (netEntity == null) {
                    callback.onFailed(-1, "后台返回数据错误");
                    return;
                }
                callback.onNewsTabNoteListComplete(netEntity);
            }

            @Override
            public void onFailure(Throwable error, FailedNetEntity bean) {
                super.onFailure(error, bean);
                callback.onFailed(bean.getCode(), bean.getMessage());
            }
        });
    }
}
